package com.detooa.detooa.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.detooa.common.annotation.Log;
import com.detooa.common.enums.BusinessType;
import com.detooa.detooa.domain.DeToOaRecord;
import com.detooa.detooa.service.IDeToOaRecordService;
import com.detooa.common.core.controller.BaseController;
import com.detooa.common.core.domain.AjaxResult;
import com.detooa.common.utils.poi.ExcelUtil;
import com.detooa.common.core.page.TableDataInfo;

/**
 * 推送记录信息Controller
 * 
 * @author detooa
 * @date 2024-01-19
 */
@Controller
@RequestMapping("/detooa/deToOaRecord")
public class DeToOaRecordController extends BaseController
{
    private String prefix = "detooa/deToOaRecord";

    @Autowired
    private IDeToOaRecordService deToOaRecordService;

    @RequiresPermissions("detooa:deToOaRecord:view")
    @GetMapping()
    public String deToOaRecord(DeToOaRecord record,ModelMap mmap)
    {
        mmap.addAttribute("record", record);
        return prefix + "/deToOaRecord";
    }

    /**
     * 查询推送记录信息列表
     */
    @RequiresPermissions("detooa:deToOaRecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DeToOaRecord deToOaRecord)
    {
        startPage();
        List<DeToOaRecord> list = deToOaRecordService.selectDeToOaRecordList(deToOaRecord);
        return getDataTable(list);
    }

    /**
     * 导出推送记录信息列表
     */
    @RequiresPermissions("detooa:deToOaRecord:export")
    @Log(title = "推送记录信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DeToOaRecord deToOaRecord)
    {
        List<DeToOaRecord> list = deToOaRecordService.selectDeToOaRecordList(deToOaRecord);
        ExcelUtil<DeToOaRecord> util = new ExcelUtil<DeToOaRecord>(DeToOaRecord.class);
        return util.exportExcel(list, "推送记录信息数据");
    }

    /**
     * 新增推送记录信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存推送记录信息
     */
    @RequiresPermissions("detooa:deToOaRecord:add")
    @Log(title = "推送记录信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DeToOaRecord deToOaRecord)
    {
        return toAjax(deToOaRecordService.insertDeToOaRecord(deToOaRecord));
    }

    /**
     * 修改推送记录信息
     */
    @RequiresPermissions("detooa:deToOaRecord:edit")
    @GetMapping("/edit/{recordId}")
    public String edit(@PathVariable("recordId") Long recordId, ModelMap mmap)
    {
        DeToOaRecord deToOaRecord = deToOaRecordService.selectDeToOaRecordByRecordId(recordId);
        mmap.put("deToOaRecord", deToOaRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存推送记录信息
     */
    @RequiresPermissions("detooa:deToOaRecord:edit")
    @Log(title = "推送记录信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DeToOaRecord deToOaRecord)
    {
        return toAjax(deToOaRecordService.updateDeToOaRecord(deToOaRecord));
    }

    /**
     * 删除推送记录信息
     */
    @RequiresPermissions("detooa:deToOaRecord:remove")
    @Log(title = "推送记录信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(deToOaRecordService.deleteDeToOaRecordByRecordIds(ids));
    }
    
    @RequiresPermissions("detooa:deToOaRecord:detail")
    @GetMapping("/detail/{recordId}")
    public String detail(@PathVariable("recordId") Long recordId, ModelMap mmap)
    {
        mmap.put("record", deToOaRecordService.selectDeToOaRecordByRecordId(recordId));
        return prefix + "/detail";
    }
}
